home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 September / macformat-028.iso / mac / Shareware City / Developers / FANTASM V3.01 / Beginners guide MS word / Video Library Example / video_demo.s < prev    next >
Encoding:
Text File  |  1995-04-03  |  5.3 KB  |  193 lines  |  [TEXT/R*ch]

  1. video_demo:
  2.  
  3. **Set up equates for box size
  4. box_top:    equ    100
  5. box_left:    equ    60
  6. box_bottom:    equ    360    box hiegth is 260
  7. box_right:    equ    580    box width is 520
  8. **eautes for blob limits
  9. blob_max_left:    equ    box_left
  10. blob_max_right:    equ    box_right-32    **32 is width of icl8
  11. blob_max_top:    equ    box_top
  12. blob_max_bottom:    equ    box_bottom-32
  13.  
  14. outer_border:    equ    34    width of the outer border
  15. border:        equ    15    width of the inner border
  16. purple:        equ    31    colour purple
  17. red:    equ    70
  18. black:        equ    255    colour black
  19.  
  20. blob_id:    equ    128    the blob is icl8 ID 128
  21. ************global variables
  22. blob_pointer:    globoff.l    1    pointer to blob grafic data
  23. blob_handle:    globoff.l    1    handle to blob grafic data
  24. owch_handle:    globoff.l    1    handle of owch sound
  25. eek_handle:    globoff.l    1    handle off eek sound
  26. *********************************************************************************        
  27.         bsr    a5_init        *mandatory
  28.         bsr    init_mac    *mandatory
  29.         bsr    init_graph_lib    *initialise the graphics library
  30.         bsr    hide_mouse    hide the mouse cursor
  31.  
  32.         move.l    #1024,d0        *get 1k for icl8 to live in
  33.         bsr    getmem    
  34.         bsr    lockmem            *lock it
  35.         move.l    a0,blob_handle(a5)    *so we can dispose it when we quit
  36.         move.l    (a0),a0            *get pointer to the memory
  37.         move.l    a0,blob_pointer(a5)
  38. **draw a red box
  39.         move.w    #red,d0
  40.         move.w    #box_left-outer_border,d1
  41.         move.w    #box_right+outer_border,d2
  42.         move.w    #box_top-outer_border,d3
  43.         move.w    #box_bottom+outer_border,d4
  44.         bsr    box_256
  45. **draw a purple box
  46.         move.w    #purple,d0    colour purple
  47.         move.w    #box_left-border,d1    start x
  48.         move.w    #box_right+border,d2    end x
  49.         move.w    #box_top-border,d3    start y
  50.         move.w    #box_bottom+border,d4    end y
  51.         bsr    box_256
  52. **now a black box inside it to make a window
  53.         move.w    #black,d0    colour=black
  54.         move.w    #box_left,d1    start x
  55.         move.w    #box_right,d2    end x
  56.         move.w    #box_top,d3    start y
  57.         move.w    #box_bottom,d4    end y
  58.         bsr    box_256
  59. **print the title
  60.         lea    hello_string(pc),a0    print box title
  61.         move.w    #7,d1    x
  62.         move.w    #7,d2    y
  63.         move.w    #52,d0    colour
  64.         bsr    print_string_8
  65.  
  66. **get owch sound.
  67.  
  68.         move.w    #128,d0
  69.         bsr    get_sound    handle in a0
  70.         move.l    a0,d0
  71.         move.l    d0,owch_handle(a5)
  72.  
  73. **get eek sound
  74.         move.w    #129,d0
  75.         bsr    get_sound
  76.         move.l    a0,d0
  77.         move.l    d0,eek_handle(a5)
  78. **now get the sprite
  79.         MOVE.W    #blob_id,D0    icl8 ID
  80.         move.l    blob_pointer(a5),A1    *get_icl8 needs to know where to put it.
  81.         BSR    GET_ICL8    load in the blob icl8 at my_data
  82.         TST.W    D0
  83.         BMI.S    QUIT        couldn't find it!
  84.         
  85.         move.l    blob_pointer(a5),A1    point to blob data
  86. **now set up vectors
  87. blob_x:        requ    d0
  88. blob_y:        requ    d1
  89. vector_x:    requ    d5
  90. vector_y:    requ    d6
  91.     
  92.  
  93.         move.w    #1,`vector_x    x vector - speed=1 pix per frame
  94.         move.w    #1,`vector_y    y vector - speed=1 pix per frame
  95.         
  96.         move.w    #200,`blob_x        initial starting position
  97.         move.w    #200,`blob_y
  98.  
  99. bounce_loop:
  100. ;        movem.l    d0-d2/a1,-(sp)     uncomment these lines to add a 1 tick delay
  101. ;        move.l    #1,d0        wait for two ticks.
  102. ;        bsr    wait
  103. ;        movem.l    (sp)+,d0-d2/a1
  104.         
  105.         bsr    icl8_print    draw the blob
  106.         
  107.         add.w    `vector_x,`blob_x    update position
  108.         add.w    `vector_y,`blob_y
  109.         
  110.         bsr.s    check_boundries        check and adjust vectors if necessary.
  111.         movem.l    d0-d1/a1,-(sp)        *save x,y and pointer to blob
  112.         bsr    plot_a_star        plot a random star
  113.         bsr    getkey_turbo        **see manual for keymapping
  114.         tst.w    d0
  115.         bmi.s    quit        *key pressed
  116.         movem.l    (sp)+,d0-d1/a1
  117.         bra.s    bounce_loop
  118. QUIT:        movem.l    (sp)+,d0-d1/a1
  119.         bsr    show_mouse    mouse cursor back on
  120.         move.l    blob_handle(a5),a0
  121.         bsr    releasemem
  122.         rts            *end of prog.
  123.         
  124. *********************Misc subroutines**********************
  125. check_boundries:    
  126. **we check blob_x and y and if close to the box boundries we reverse the relevant
  127. **vector.
  128.         cmpi.w    #blob_max_left,`blob_x
  129.         bgt.s    not_min_x    hasn't passed minimum x boundry
  130.         neg.w    `vector_x    reverse the x vector
  131.         bra.s    done_x        check y
  132. not_min_x:    cmpi.w    #blob_max_right,`blob_x
  133.         blt.s    done_x
  134.         neg.w    `vector_x
  135. done_x:        cmpi.w    #blob_max_top,`blob_y
  136.         bgt.s    not_min_y
  137.         neg.w    `vector_y
  138.         
  139.         movem.l    d0-d1,-(sp)    save coords
  140.         bsr    random
  141.         andi.w    #$f,d0        gt a random number less than 16
  142.         cmpi.w    #2,d0        if its greater than 2 then dont go owch
  143.         bge.s    dont_go_owch
  144.         move.l    owch_handle(a5),a0
  145.         bsr    run_sound    make owch sound
  146. dont_go_owch:
  147.         movem.l    (sp)+,d0-d1    get coords back
  148.         bra.s    done_y
  149.         
  150. not_min_y:    cmpi.w    #blob_max_bottom,`blob_y
  151.         blt.s    done_y
  152.         neg.w    `vector_y
  153.         movem.l    d0-d1,-(sp)    save coords
  154.         bsr    random
  155.         andi.w    #$f,d0        gt a random number less than 16
  156.         cmpi.w    #2,d0        if its greater than 2 then dont go eek
  157.         bge.s    dont_go_eek
  158.         move.l    eek_handle(a5),a0
  159.         bsr    run_sound    make owch sound
  160. dont_go_eek:    movem.l    (sp)+,d0-d1    restore coords
  161.  
  162. done_y:        rts
  163.  
  164. ***********
  165.  
  166. **plot_a_star calls random to get values for a star position and colour.
  167. plot_a_star:    bsr    random        get long random number in d0
  168.         andi.w    #$f,d0        make less than 16
  169.         cmpi.w    #1,d0
  170.         blt.s    do_star        if less than 4 then do a start (1 in 16 chance)
  171.         rts
  172. do_star:
  173.         bsr    random
  174.         andi.l    #$1ff,d0        make in the range of 0-511
  175.         add.w    #box_left,d0
  176.         move.w    d0,d7        save x coord
  177.         bsr    random
  178.         andi.l    #$ff,d0
  179.         add.w    #box_top,d0
  180.         move.w    d0,d2        *y coord
  181.         move.w    d7,d1        *x coord
  182.         bsr    plot_256    *plot it
  183.         rts
  184.         
  185.  
  186. hello_string:    dc.b    "The annoying Blob - An Example for Fantasm V3.00.",0
  187.         even
  188.         global    video_demo
  189.         extern    init_mac,a5_init
  190.         extern    init_graph_lib,box_256,getkey_turbo,random
  191.         extern    icl8_print,GET_ICL8,plot_256,wait
  192.         extern    hide_mouse,show_mouse,print_char_8,print_string_8
  193.         extern    getmem,lockmem,releasemem,get_sound,run_sound